<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StateDAO
 * Created Date - 4/12/2012
 * @author gaurav
 */





class StateDAO implements State {

       public function getState(){
      
              // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$STATE_COL_STATE_ID . "," .Constant::$STATE_COL_STATE_NAME ." FROM ".Constant::$TABLE_STATE;

        $result = mysql_query($sql);
        $allStateArray[] = Array();
        $i = 0;
        while($row = mysql_fetch_assoc($result)) {
            $tempState = new StateDTO();
            $tempState->setId($row[Constant::$STATE_COL_STATE_ID]);
            $tempState->setName($row[Constant::$STATE_COL_STATE_NAME]);

             $allStateArray[$i] = $tempState;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$STATE_COL_STATE_ID]. " State Name : ". $row[Constant::$STATE_COL_STATE_NAME]);
            }
            $i++;
          //  echo $i;
            //echo "<br />";
        }
         
        return $allStateArray;
       }

       public function getStateByCountryId($countryId){

           // implementation of this method is pending till we finalize the we want to make country table or not.

       }
	public function getStateById($counrtyId,$stateId){

                    // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$STATE_COL_STATE_ID . "," .Constant::$STATE_COL_STATE_NAME ." FROM ".Constant::$TABLE_STATE . " where ". Constant::$STATE_COL_STATE_ID . " = ".$stateId;
        
        $result = mysql_query($sql);
        $allStateArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempState = new StateDTO();
            $tempState->setId($row[Constant::$STATE_COL_STATE_ID]);
            $tempState->setName($row[Constant::$STATE_COL_STATE_NAME]);

            $allStateArray[] = $tempCity;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$STATE_COL_STATE_ID]. " State Name : ". $row[Constant::$STATE_COL_STATE_NAME]);
            }

            //echo "<br />";
        }
        return $allStateArray;
        }
	public function setState($countryId, $stateName){

             // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        //  $sql = "SELECT ". Constant::$COL_ID. "," .Constant::$COL_STATE_ID .",".Constant::$COL_NAME." FROM ".Constant::$TABLE_CITY . "  where ".Constant::$COL_ID."= ".$cityId;
        $sql = "INSERT INTO ".Constant::$TABLE_STATE." (".Constant::$STATE_COL_STATE_NAME." ) VALUES ('".$stateName."')";

        $result = mysql_query($sql);
        if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }

        mysql_close($connection);
        }
	public function setStateById($countryId, $stateId, $stateName){

              // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "UPDATE ".Constant::$TABLE_STATE." SET ".Constant::$STATE_COL_STATE_NAME." = '".$stateName."' WHERE ".Constant::$STATE_COL_STATE_ID." = '".$stateId."'";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);
        }
	public function removeStateByCounrtyId($counrtyId){

            // this method is pening till contry table finallize
        }
	public function removeStateById($countryId, $stateId){

              // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_STATE." where ".Constant::$STATE_COL_STATE_ID." = ".$stateId."";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);
        }
}
?>
